package com.sinsz.common.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * @author chenjianbo
 * @date 2018-11-30
 */
@Validated
@ConfigurationProperties("sinsz.common")
public class CommonProperties {

    /**
     * 请求头信息记录
     */
    private Map<String, String> headers;

    /**
     * Rpc配置
     */
    @Valid
    private Bolt bolt;

    /**
     * 是否启用Rpc,true启用,false不启用
     */
    private boolean enableBolt;

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public Bolt getBolt() {
        return bolt;
    }

    public void setBolt(Bolt bolt) {
        this.bolt = bolt;
    }

    public boolean isEnableBolt() {
        return enableBolt;
    }

    public void setEnableBolt(boolean enableBolt) {
        this.enableBolt = enableBolt;
    }

    public static class Bolt {

        /**
         * 应用名称
         */
        @NotEmpty
        private String appName;

        /**
         * zookeeper集群地址,示例:192.168.1.2:2181,192.168.1.3:2181,192.168.1.4:2181
         */
        @NotEmpty
        private String zkCluster;

        /**
         * 服务发布端口号
         */
        @NotNull
        private Integer port;

        /**
         * 服务发布IP地址
         */
        @NotEmpty
        private String boundHost;

        /**
         * 访问超时
         */
        private Integer timeout = 10000;

        /**
         * 连接超时
         */
        private Integer connectTimeout = 10000;

        /**
         * 重试次数
         */
        private Integer retries = 3;

        /**
         * 熔断超时时间
         */
        private Integer hystrixTimeout = 5000;

        public String getAppName() {
            return appName;
        }

        public void setAppName(String appName) {
            this.appName = appName;
        }

        public String getZkCluster() {
            return zkCluster;
        }

        public void setZkCluster(String zkCluster) {
            this.zkCluster = zkCluster;
        }

        public Integer getPort() {
            return port;
        }

        public void setPort(Integer port) {
            this.port = port;
        }

        public String getBoundHost() {
            return boundHost;
        }

        public void setBoundHost(String boundHost) {
            this.boundHost = boundHost;
        }

        public Integer getTimeout() {
            return timeout;
        }

        public void setTimeout(Integer timeout) {
            this.timeout = timeout;
        }

        public Integer getConnectTimeout() {
            return connectTimeout;
        }

        public void setConnectTimeout(Integer connectTimeout) {
            this.connectTimeout = connectTimeout;
        }

        public Integer getRetries() {
            return retries;
        }

        public void setRetries(Integer retries) {
            this.retries = retries;
        }

        public Integer getHystrixTimeout() {
            return hystrixTimeout;
        }

        public void setHystrixTimeout(Integer hystrixTimeout) {
            this.hystrixTimeout = hystrixTimeout;
        }
    }

}
